//
//  TLDate
//  Extends the builtin date class with functions to add and subtract months.
//  BEWARE! Constructor only supports the date, no time.
//
//  Created by Ryan Mark on 2008-08-12.
//  Copyright (c) 2008 __MyCompanyName__. All rights reserved.
//

class com.ryanmark.TLDate 
extends Date
{
  
  
  function TLDate(yearOrTimevalue:Number, month:Number, date:Number)
  {
    super(yearOrTimevalue,month,date);
  }
	
	function advanceMonth(num:Number):Void
	{
	  if(getMonth()+num <= 11)
	    setMonth(getMonth()+num)
	  else
	  {
	    var addYears:Number = Math.floor((getMonth()+num)/12);
	    var newMonth:Number = getMonth()+num - addYears*12;
	    setFullYear(getFullYear()+addYears);
	    setMonth(newMonth);
	  }
	}
	
	function reverseMonth(num:Number):Void
	{
	  if(getMonth()-num >= 0)
	    setMonth(getMonth()-num)
	  else
	  {
	    var removeYears:Number = Math.ceil(Math.abs(getMonth()-num)/12);
	    var newMonth:Number = getMonth()-num + removeYears*12;
	    setFullYear(getFullYear()-removeYears);
	    setMonth(newMonth);
	  }
	}
	
	function compareMonth(pDt:Date):Number
	{
	  var yrDiff = pDt.getFullYear()-getFullYear();
	  var monDiff = pDt.getMonth()-getMonth();
	  return monDiff+(yrDiff*12);
	}
	
	function getActMonthDays():Number { 
     return (new Date(this.getFullYear(),this.getMonth()+1,0).getDate()); 
  }
}